<?php
declare (strict_types=1);

namespace app\user\model\user;

use app\common\model\BaseModel;

/**
 * 定义活动数据模型
 */
class Ticket extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'market_ticket';

    /**
     * 全局查询范围
     *
     * @var [type]
     */
    protected $globalScope = ['mhm', 'status'];

    /**
     * 限制机构条件
     *
     * @param $query
     */
    public function scopeMhm($query)
    {
        $query->where('mhm_id', request()->mhm_id);
    }

    /**
     * scopeStatus
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 23/07/13
     *
     * @param $query
     */
    public function scopeStatus($query)
    {
        $query->where('status', 1);
    }

    /**
     * scopeTarget
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 23/07/13
     *
     * @param $query
     * @param string $target
     */
    public function scopeTarget($query, string $target = '0')
    {
        $query->where('target_user_type', $target);
    }

    /**
     * scopeTargetIn
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 23/07/13
     *
     * @param $query
     * @param string $target
     */
    public function scopeTargetIn($query, string $target = '0')
    {
        $query->whereIn('target_user_type', $target);
    }

}
